package orchestration.android.demo;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

public class ExitOrBackToStartActivity extends Activity{

	@Override
	protected void onResume() {
		super.onResume();
		showDialog(7);
		
	}
	protected Dialog onCreateDialog(int id) { 
		String action= getIntent().getAction();
		String question = "General";
		if(action.equals("orchestration.demo.action.ASK_LOAN"))
			question="Loan?";
		else if(action.equals("orchestration.demo.action.ASK_EXIT"))
			question="Exit?";
		return new AlertDialog.Builder(ExitOrBackToStartActivity.this) 
		.setTitle(question) 
		.setPositiveButton("Ok!", new 
				DialogInterface.OnClickListener() { 
			public void onClick(DialogInterface dialog, int 
					whichButton) { 
				saveExtrasAndFinish(true);
			} 
		}) 
		.setNegativeButton("No", new 
				DialogInterface.OnClickListener() { 
			public void onClick(DialogInterface dialog, int 
					whichButton) { 
				saveExtrasAndFinish(false);
			} 
		}) 
		.setOnCancelListener(new
				DialogInterface.OnCancelListener() {
					
					@Override
					public void onCancel(DialogInterface dialog) {
						ExitOrBackToStartActivity.this.finish();
					}
				}).create(); 
	}
	void saveExtrasAndFinish(boolean result) {
		Bundle b= new Bundle();
		b.putBoolean("result", result);
		Intent i = new Intent();
		i.putExtras(b);
		this.setResult(RESULT_OK,i);
		finish();
	} 
}
